
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

class FlutterBdfacePlugin {
  static const MethodChannel _channel =
      const MethodChannel('flutter_bdface_plugin');

  static Future<String> get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  Future initIosSdk(String iosLicId) async {
    var arguments = Map();
    arguments['iosLicId'] = iosLicId;
    _channel.invokeMethod('initIosSdk', arguments);
  }

  Future<LivenessResult> liveness({language = 'zh'}) async {
    var arguments = Map();
    arguments['language'] = language;
    final Map<dynamic, dynamic> map =
    await _channel.invokeMethod('liveness', arguments);
    return map != null ? new LivenessResult.fromMap(map) : null;
  }

  Future<DetectResult> detect({language = 'zh'}) async {
    var arguments = Map();
    arguments['language'] = language;
    final Map<dynamic, dynamic> map =
    await _channel.invokeMethod('detect', arguments);
    return map != null ? new DetectResult.fromMap(map) : null;
  }
}

class LivenessResult {
  LivenessResult({@required this.success, @required this.image});
  factory LivenessResult.fromMap(Map<dynamic, dynamic> map) =>
      new LivenessResult(
        success: map['success'],
        image: map['srcimage']
      );
  final String success;
  // sucess=true
  final String image;
  @override
  String toString() => 'LivenessResult: $success,$image';
}

class DetectResult {
  DetectResult({@required this.success, @required this.image});

  factory DetectResult.fromMap(Map<dynamic, dynamic> map) => new DetectResult(
    success: map['success'],
    image: map['srcimage']
  );
  final String success;
  // sucess=true
  final String image;
  @override
  String toString() => 'DetectResult: $success,$image';
}


